<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>从零开始搭建信贷管理系统 | SPEED 团队企业级中台组件</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="$withBase(&#39;/avatar.png&#39;)">
    <meta name="description" content="">
    
    <link rel="preload" href="/assets/css/0.styles.4a390c75.css" as="style"><link rel="preload" href="/assets/js/app.9e59f384.js" as="script"><link rel="preload" href="/assets/js/2.61252cf6.js" as="script"><link rel="preload" href="/assets/js/13.a9ff20a6.js" as="script"><link rel="prefetch" href="/assets/js/10.47abf4f2.js"><link rel="prefetch" href="/assets/js/11.f25fa446.js"><link rel="prefetch" href="/assets/js/12.b817a6b9.js"><link rel="prefetch" href="/assets/js/14.5f5c406e.js"><link rel="prefetch" href="/assets/js/3.a4b7a9d2.js"><link rel="prefetch" href="/assets/js/4.8bbc0415.js"><link rel="prefetch" href="/assets/js/5.64a3d90d.js"><link rel="prefetch" href="/assets/js/6.65875694.js"><link rel="prefetch" href="/assets/js/7.c347ceab.js"><link rel="prefetch" href="/assets/js/8.07cb2ef7.js"><link rel="prefetch" href="/assets/js/9.be610aef.js">
    <link rel="stylesheet" href="/assets/css/0.styles.4a390c75.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/avatar.png" alt="SPEED 团队企业级中台组件" class="logo"> <span class="site-name can-hide">SPEED 团队企业级中台组件</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link">
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="业务中台" class="dropdown-title"><span class="title">业务中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="业务中台" class="mobile-dropdown-title"><span class="title">业务中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/业务中台组件/登录认证授权组件.html" class="nav-link">
  登录认证授权组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/数据脱敏组件.html" class="nav-link">
  数据脱敏组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/OBS 对象存储组件.html" class="nav-link">
  OBS 对象存储组件
</a></li><li class="dropdown-item"><!----> <a href="/业务中台组件/邮件发送组件.html" class="nav-link">
  邮件发送组件
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据中台" class="dropdown-title"><span class="title">数据中台</span> <span class="arrow down"></span></button> <button type="button" aria-label="数据中台" class="mobile-dropdown-title"><span class="title">数据中台</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/数据中台组件/钉钉告警组件.html" class="nav-link">
  钉钉告警组件
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>业务中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/业务中台组件/登录认证授权组件.html" class="sidebar-link">登录认证授权组件</a></li><li><a href="/业务中台组件/数据脱敏组件.html" class="sidebar-link">数据脱敏组件</a></li><li><a href="/业务中台组件/OBS 对象存储组件.html" class="sidebar-link">OBS 对象存储组件</a></li><li><a href="/业务中台组件/邮件发送组件.html" class="sidebar-link">邮件发送组件</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>数据中台</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/数据中台组件/钉钉告警组件.html" class="sidebar-link">钉钉告警组件</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="从零开始搭建信贷管理系统"><a href="#从零开始搭建信贷管理系统" class="header-anchor">#</a> 从零开始搭建信贷管理系统</h1> <h1 id="_1-技术栈-项目架构选型"><a href="#_1-技术栈-项目架构选型" class="header-anchor">#</a> 1.技术栈 &amp;&amp; 项目架构选型</h1> <ul><li><p>技术栈</p> <p><strong>SpringBoot、Redis、MySQL、Maven、Vue、Security、Mybatis plus。</strong></p></li></ul> <div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>SpringBoot: 后端项目脚手架</p> <p>Redis: 数据缓存</p> <p>MySQL: 数据持久化</p> <p>Maven: 项目管理</p> <p>Vue: 前端框架</p> <p>Security: 安全认证授权框架</p> <p>Mybatis plus: 持久化框架</p></div> <ul><li><p>项目架构选型</p> <p>前后端分离</p></li> <li><p>业务架构</p> <p><img src="C:%5CUsers%5Ctlgen%5CDownloads%5C%E4%BF%A1%E8%B4%B7%E5%8D%95%E4%BD%93%E7%BB%93%E6%9E%84%E9%A1%B9%E7%9B%AE%E6%9E%B6%E6%9E%84%E5%9B%BE.png" alt="信贷单体结构项目架构图"></p></li></ul> <h1 id="_2-后端项目搭建"><a href="#_2-后端项目搭建" class="header-anchor">#</a> 2.后端项目搭建</h1> <h1 id="_3-持久层框架"><a href="#_3-持久层框架" class="header-anchor">#</a> 3.持久层框架</h1> <ul><li><h3 id="引入-mybatis-plus-分页插件支持"><a href="#引入-mybatis-plus-分页插件支持" class="header-anchor">#</a> 引入 Mybatis plus &amp;&amp; 分页插件支持</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>github<span class="token punctuation">.</span>pagehelper<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>pagehelper<span class="token operator">-</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">1.4</span><span class="token number">.1</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>

        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>com<span class="token punctuation">.</span>baomidou<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>mybatis<span class="token operator">-</span>plus<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">3.5</span><span class="token number">.1</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div></li> <li><h3 id="分页插件配置"><a href="#分页插件配置" class="header-anchor">#</a> 分页插件配置</h3> <blockquote><div class="language-ruby extra-class"><pre class="language-ruby"><code>分页插件 <span class="token number">3.5</span><span class="token punctuation">.</span><span class="token constant">X</span> 版本<span class="token punctuation">,</span> 以下为高版本配置方式
</code></pre></div></blockquote> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>common<span class="token punctuation">.</span>config<span class="token punctuation">;</span>

import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>DbType<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>extension<span class="token punctuation">.</span>plugins<span class="token punctuation">.</span>MybatisPlusInterceptor<span class="token punctuation">;</span>
import com<span class="token punctuation">.</span>baomidou<span class="token punctuation">.</span>mybatisplus<span class="token punctuation">.</span>extension<span class="token punctuation">.</span>plugins<span class="token punctuation">.</span>inner<span class="token punctuation">.</span>PaginationInnerInterceptor<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Bean<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Configuration<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>transaction<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>EnableTransactionManagement<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Collections<span class="token punctuation">;</span>

<span class="token operator">/</span><span class="token operator">**</span>
 <span class="token operator">*</span> 配置分页插件<span class="token punctuation">,</span> 需引入分页插件<span class="token punctuation">,</span> 解决查询总数一直为 <span class="token number">0</span> 的问题<span class="token punctuation">,</span>
 <span class="token operator">*</span> 注意版本问题<span class="token punctuation">,</span> 版本太低可能会导致 jar 冲突
 <span class="token operator">*</span><span class="token operator">/</span>
<span class="token variable">@EnableTransactionManagement</span>
<span class="token variable">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">MybatisPlusConfig</span> <span class="token punctuation">{</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 分页插件 <span class="token number">3.5</span><span class="token punctuation">.</span><span class="token constant">X</span> 版本
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Bean</span>
    <span class="token keyword">public</span> PaginationInnerInterceptor paginationInnerInterceptor<span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        PaginationInnerInterceptor paginationInterceptor <span class="token operator">=</span> <span class="token keyword">new</span> PaginationInnerInterceptor<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 设置最大单页限制数量，默认 <span class="token number">500</span> 条，<span class="token operator">-</span><span class="token number">1</span> 不受限制
        paginationInterceptor<span class="token punctuation">.</span>setMaxLimit<span class="token punctuation">(</span><span class="token operator">-</span><span class="token number">1</span>L<span class="token punctuation">)</span><span class="token punctuation">;</span>
        paginationInterceptor<span class="token punctuation">.</span>setDbType<span class="token punctuation">(</span>DbType<span class="token punctuation">.</span><span class="token constant">MYSQL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 开启 count 的 join 优化<span class="token punctuation">,</span> 只针对部分 left join
        paginationInterceptor<span class="token punctuation">.</span>setOptimizeJoin<span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> paginationInterceptor<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token variable">@Bean</span>
    <span class="token keyword">public</span> MybatisPlusInterceptor mybatisPlusInterceptor<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        MybatisPlusInterceptor mybatisPlusInterceptor <span class="token operator">=</span> <span class="token keyword">new</span> MybatisPlusInterceptor<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        mybatisPlusInterceptor<span class="token punctuation">.</span>setInterceptors<span class="token punctuation">(</span>Collections<span class="token punctuation">.</span>singletonList<span class="token punctuation">(</span>paginationInnerInterceptor<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> mybatisPlusInterceptor<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div></li></ul> <h1 id="_4-缓存管理"><a href="#_4-缓存管理" class="header-anchor">#</a> 4.缓存管理</h1> <h3 id="集成-redis"><a href="#集成-redis" class="header-anchor">#</a> 集成 Redis</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">-</span>data<span class="token operator">-</span>redis<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h1 id="_5-登录认证"><a href="#_5-登录认证" class="header-anchor">#</a> 5.登录认证</h1> <h3 id="security-安全权限框架"><a href="#security-安全权限框架" class="header-anchor">#</a> Security 安全权限框架</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>boot<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>spring<span class="token operator">-</span>boot<span class="token operator">-</span>starter<span class="token operator">-</span>security<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h3 id="jwt-令牌"><a href="#jwt-令牌" class="header-anchor">#</a> Jwt 令牌</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>        <span class="token operator">&lt;</span>dependency<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>groupId<span class="token operator">&gt;</span>io<span class="token punctuation">.</span>jsonwebtoken<span class="token operator">&lt;</span><span class="token operator">/</span>groupId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>artifactId<span class="token operator">&gt;</span>jjwt<span class="token operator">&lt;</span><span class="token operator">/</span>artifactId<span class="token operator">&gt;</span>
            <span class="token operator">&lt;</span>version<span class="token operator">&gt;</span><span class="token number">0.9</span><span class="token number">.1</span><span class="token operator">&lt;</span><span class="token operator">/</span>version<span class="token operator">&gt;</span>
        <span class="token operator">&lt;</span><span class="token operator">/</span>dependency<span class="token operator">&gt;</span>
</code></pre></div><h3 id="通用常量类"><a href="#通用常量类" class="header-anchor">#</a> 通用常量类</h3> <div class="language- extra-class"><pre class="language-text"><code>package com.tlgen.constant;

/**
 * 通用常量信息
*/
public class Constants
{
    /**
     * 验证码 redis key
     */
    public static final String CAPTCHA_CODE_KEY = &quot;captcha_codes:&quot;;

    /**
     * 登录用户 redis key
     */
    public static final String LOGIN_TOKEN_KEY = &quot;login_tokens:&quot;;

    /**
     * 令牌
     */
    public static final String TOKEN = &quot;token&quot;;

    /**
     * 令牌前缀
     */
    public static final String TOKEN_PREFIX = &quot;Bearer &quot;;

    /**
     * 令牌前缀
     */
    public static final String LOGIN_USER_KEY = &quot;login_user_key&quot;;

}

</code></pre></div><h3 id="状态码常量类"><a href="#状态码常量类" class="header-anchor">#</a> 状态码常量类</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>constant<span class="token punctuation">;</span>

<span class="token operator">/</span><span class="token operator">**</span>
 <span class="token operator">*</span> 返回状态码
<span class="token operator">*</span><span class="token operator">/</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">HttpStatus</span>
<span class="token punctuation">{</span>
    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 操作成功
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">SUCCESS</span> <span class="token operator">=</span> <span class="token number">200</span><span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 请求参数错误
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">BAD_REQUEST</span> <span class="token operator">=</span> <span class="token number">400</span><span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 未授权
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">UNAUTHORIZED</span> <span class="token operator">=</span> <span class="token number">401</span><span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 访问受限，授权过期
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">FORBIDDEN</span> <span class="token operator">=</span> <span class="token number">403</span><span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 资源，服务未找到
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">NOT_FOUND</span> <span class="token operator">=</span> <span class="token number">404</span><span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 系统内部错误
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> static final int <span class="token constant">ERROR</span> <span class="token operator">=</span> <span class="token number">500</span><span class="token punctuation">;</span>

<span class="token punctuation">}</span>

</code></pre></div><h3 id="redis-工具类"><a href="#redis-工具类" class="header-anchor">#</a> Redis 工具类</h3> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>security<span class="token punctuation">.</span>redis<span class="token punctuation">;</span>

import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Collection<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>List<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Map<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>Set<span class="token punctuation">;</span>
import java<span class="token punctuation">.</span>util<span class="token punctuation">.</span>concurrent<span class="token punctuation">.</span>TimeUnit<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>beans<span class="token punctuation">.</span>factory<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Autowired<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>data<span class="token punctuation">.</span>redis<span class="token punctuation">.</span>core<span class="token punctuation">.</span>HashOperations<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>data<span class="token punctuation">.</span>redis<span class="token punctuation">.</span>core<span class="token punctuation">.</span>RedisTemplate<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>data<span class="token punctuation">.</span>redis<span class="token punctuation">.</span>core<span class="token punctuation">.</span>ValueOperations<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>stereotype<span class="token punctuation">.</span>Component<span class="token punctuation">;</span>

<span class="token operator">/</span><span class="token operator">**</span>
 <span class="token operator">*</span> spring redis 工具类

 <span class="token operator">**</span><span class="token operator">/</span>
<span class="token variable">@SuppressWarnings</span><span class="token punctuation">(</span>value <span class="token operator">=</span> <span class="token punctuation">{</span> <span class="token string-literal"><span class="token string">&quot;unchecked&quot;</span></span><span class="token punctuation">,</span> <span class="token string-literal"><span class="token string">&quot;rawtypes&quot;</span></span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token variable">@Component</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">RedisCache</span>
<span class="token punctuation">{</span>
    <span class="token variable">@Autowired</span>
    <span class="token keyword">public</span> RedisTemplate redisTemplate<span class="token punctuation">;</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 缓存基本的对象，<span class="token builtin">Integer</span>、<span class="token builtin">String</span>、实体类等
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存的键值
     <span class="token operator">*</span> <span class="token variable">@param</span> value 缓存的值
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> void setCacheObject<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final <span class="token constant">T</span> value<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        redisTemplate<span class="token punctuation">.</span>opsForValue<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>set<span class="token punctuation">(</span>key<span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 缓存基本的对象，<span class="token builtin">Integer</span>、<span class="token builtin">String</span>、实体类等
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存的键值
     <span class="token operator">*</span> <span class="token variable">@param</span> value 缓存的值
     <span class="token operator">*</span> <span class="token variable">@param</span> timeout 时间
     <span class="token operator">*</span> <span class="token variable">@param</span> timeUnit 时间颗粒度
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> void setCacheObject<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final <span class="token constant">T</span> value<span class="token punctuation">,</span> final <span class="token builtin">Integer</span> timeout<span class="token punctuation">,</span> final TimeUnit timeUnit<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        redisTemplate<span class="token punctuation">.</span>opsForValue<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>set<span class="token punctuation">(</span>key<span class="token punctuation">,</span> value<span class="token punctuation">,</span> timeout<span class="token punctuation">,</span> timeUnit<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 设置有效时间
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key Redis键
     <span class="token operator">*</span> <span class="token variable">@param</span> timeout 超时时间
     <span class="token operator">*</span> <span class="token variable">@return</span> <span class="token boolean">true</span><span class="token operator">=</span>设置成功；<span class="token boolean">false</span><span class="token operator">=</span>设置失败
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> boolean expire<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final long timeout<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> expire<span class="token punctuation">(</span>key<span class="token punctuation">,</span> timeout<span class="token punctuation">,</span> TimeUnit<span class="token punctuation">.</span><span class="token constant">SECONDS</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 设置有效时间
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key Redis键
     <span class="token operator">*</span> <span class="token variable">@param</span> timeout 超时时间
     <span class="token operator">*</span> <span class="token variable">@param</span> unit 时间单位
     <span class="token operator">*</span> <span class="token variable">@return</span> <span class="token boolean">true</span><span class="token operator">=</span>设置成功；<span class="token boolean">false</span><span class="token operator">=</span>设置失败
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> boolean expire<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final long timeout<span class="token punctuation">,</span> final TimeUnit unit<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>expire<span class="token punctuation">(</span>key<span class="token punctuation">,</span> timeout<span class="token punctuation">,</span> unit<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获得缓存的基本对象。
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存键值
     <span class="token operator">*</span> <span class="token variable">@return</span> 缓存键值对应的数据
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> <span class="token constant">T</span> getCacheObject<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        ValueOperations<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token constant">T</span><span class="token operator">&gt;</span> operation <span class="token operator">=</span> redisTemplate<span class="token punctuation">.</span>opsForValue<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> operation<span class="token punctuation">.</span>get<span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 删除单个对象
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> boolean deleteObject<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>delete<span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 删除集合对象
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> collection 多个对象
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> long deleteObject<span class="token punctuation">(</span>final Collection collection<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>delete<span class="token punctuation">(</span>collection<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 缓存List数据
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存的键值
     <span class="token operator">*</span> <span class="token variable">@param</span> dataList 待缓存的List数据
     <span class="token operator">*</span> <span class="token variable">@return</span> 缓存的对象
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> long setCacheList<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final List<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> dataList<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        Long count <span class="token operator">=</span> redisTemplate<span class="token punctuation">.</span>opsForList<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>rightPushAll<span class="token punctuation">(</span>key<span class="token punctuation">,</span> dataList<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> count <span class="token operator">==</span> null <span class="token operator">?</span> <span class="token number">0</span> <span class="token operator">:</span> count<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获得缓存的list对象
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存的键值
     <span class="token operator">*</span> <span class="token variable">@return</span> 缓存键值对应的数据
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> List<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> getCacheList<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>opsForList<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>range<span class="token punctuation">(</span>key<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 缓存Set
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key 缓存键值
     <span class="token operator">*</span> <span class="token variable">@param</span> dataSet 缓存的数据
     <span class="token operator">*</span> <span class="token variable">@return</span> 缓存数据的对象
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> long setCacheSet<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final Set<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> dataSet<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        Long count <span class="token operator">=</span> redisTemplate<span class="token punctuation">.</span>opsForSet<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>add<span class="token punctuation">(</span>key<span class="token punctuation">,</span> dataSet<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> count <span class="token operator">==</span> null <span class="token operator">?</span> <span class="token number">0</span> <span class="token operator">:</span> count<span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获得缓存的set
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> Set<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> getCacheSet<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>opsForSet<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>members<span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 缓存Map
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key
     <span class="token operator">*</span> <span class="token variable">@param</span> dataMap
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> void setCacheMap<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final Map<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token constant">T</span><span class="token operator">&gt;</span> dataMap<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">if</span> <span class="token punctuation">(</span>dataMap <span class="token operator">!=</span> null<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>putAll<span class="token punctuation">(</span>key<span class="token punctuation">,</span> dataMap<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获得缓存的Map
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key
     <span class="token operator">*</span> <span class="token variable">@return</span>
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> Map<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token constant">T</span><span class="token operator">&gt;</span> getCacheMap<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>entries<span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 往<span class="token builtin">Hash</span>中存入数据
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key Redis键
     <span class="token operator">*</span> <span class="token variable">@param</span> hKey <span class="token builtin">Hash</span>键
     <span class="token operator">*</span> <span class="token variable">@param</span> value 值
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> void setCacheMapValue<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final <span class="token builtin">String</span> hKey<span class="token punctuation">,</span> final <span class="token constant">T</span> value<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>put<span class="token punctuation">(</span>key<span class="token punctuation">,</span> hKey<span class="token punctuation">,</span> value<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获取<span class="token builtin">Hash</span>中的数据
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key Redis键
     <span class="token operator">*</span> <span class="token variable">@param</span> hKey <span class="token builtin">Hash</span>键
     <span class="token operator">*</span> <span class="token variable">@return</span> <span class="token builtin">Hash</span>中的对象
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> <span class="token constant">T</span> getCacheMapValue<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final <span class="token builtin">String</span> hKey<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        HashOperations<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token builtin">String</span><span class="token punctuation">,</span> <span class="token constant">T</span><span class="token operator">&gt;</span> opsForHash <span class="token operator">=</span> redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> opsForHash<span class="token punctuation">.</span>get<span class="token punctuation">(</span>key<span class="token punctuation">,</span> hKey<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获取多个<span class="token builtin">Hash</span>中的数据
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> key Redis键
     <span class="token operator">*</span> <span class="token variable">@param</span> hKeys <span class="token builtin">Hash</span>键集合
     <span class="token operator">*</span> <span class="token variable">@return</span> <span class="token builtin">Hash</span>对象集合
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> <span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> List<span class="token operator">&lt;</span><span class="token constant">T</span><span class="token operator">&gt;</span> getMultiCacheMapValue<span class="token punctuation">(</span>final <span class="token builtin">String</span> key<span class="token punctuation">,</span> final Collection<span class="token operator">&lt;</span><span class="token builtin">Object</span><span class="token operator">&gt;</span> hKeys<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>opsForHash<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>multiGet<span class="token punctuation">(</span>key<span class="token punctuation">,</span> hKeys<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 获得缓存的基本对象列表
     <span class="token operator">*</span>
     <span class="token operator">*</span> <span class="token variable">@param</span> pattern 字符串前缀
     <span class="token operator">*</span> <span class="token variable">@return</span> 对象列表
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token keyword">public</span> Collection<span class="token operator">&lt;</span><span class="token builtin">String</span><span class="token operator">&gt;</span> keys<span class="token punctuation">(</span>final <span class="token builtin">String</span> pattern<span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        <span class="token keyword">return</span> redisTemplate<span class="token punctuation">.</span>keys<span class="token punctuation">(</span>pattern<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

</code></pre></div><h1 id="_6-后端跨域处理"><a href="#_6-后端跨域处理" class="header-anchor">#</a> 6.后端跨域处理</h1> <div class="language-ruby extra-class"><pre class="language-ruby"><code>package com<span class="token punctuation">.</span>tlgen<span class="token punctuation">.</span>config<span class="token punctuation">;</span>

import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Bean<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>context<span class="token punctuation">.</span>annotation<span class="token punctuation">.</span>Configuration<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>cors<span class="token punctuation">.</span>CorsConfiguration<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>cors<span class="token punctuation">.</span>UrlBasedCorsConfigurationSource<span class="token punctuation">;</span>
import org<span class="token punctuation">.</span>springframework<span class="token punctuation">.</span>web<span class="token punctuation">.</span>filter<span class="token punctuation">.</span>CorsFilter<span class="token punctuation">;</span>

<span class="token variable">@Configuration</span>
<span class="token keyword">public</span> <span class="token keyword">class</span> <span class="token class-name">ResourceConfig</span> <span class="token punctuation">{</span>

    <span class="token operator">/</span><span class="token operator">**</span>
     <span class="token operator">*</span> 跨域配置
     <span class="token operator">*</span><span class="token operator">/</span>
    <span class="token variable">@Bean</span>
    <span class="token keyword">public</span> CorsFilter corsFilter<span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">{</span>
        UrlBasedCorsConfigurationSource source <span class="token operator">=</span> <span class="token keyword">new</span> UrlBasedCorsConfigurationSource<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        CorsConfiguration config <span class="token operator">=</span> <span class="token keyword">new</span> CorsConfiguration<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        config<span class="token punctuation">.</span>setAllowCredentials<span class="token punctuation">(</span><span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 设置访问源地址
        config<span class="token punctuation">.</span>addAllowedOrigin<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;*&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 设置访问源请求头
        config<span class="token punctuation">.</span>addAllowedHeader<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;*&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 设置访问源请求方法
        config<span class="token punctuation">.</span>addAllowedMethod<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;*&quot;</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token operator">/</span><span class="token operator">/</span> 对接口配置跨域设置
        source<span class="token punctuation">.</span>registerCorsConfiguration<span class="token punctuation">(</span><span class="token string-literal"><span class="token string">&quot;/**&quot;</span></span><span class="token punctuation">,</span> config<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> CorsFilter<span class="token punctuation">(</span>source<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h1 id="_7-前端项目搭建"><a href="#_7-前端项目搭建" class="header-anchor">#</a> 7.前端项目搭建</h1> <h1 id="_8-前端跨域处理"><a href="#_8-前端跨域处理" class="header-anchor">#</a> 8.前端跨域处理</h1> <h1 id="_9-封装请求响应拦截"><a href="#_9-封装请求响应拦截" class="header-anchor">#</a> 9.封装请求响应拦截</h1> <h1 id="_10-全局路由守卫"><a href="#_10-全局路由守卫" class="header-anchor">#</a> 10.全局路由守卫</h1> <h1 id="_11-状态管理"><a href="#_11-状态管理" class="header-anchor">#</a> 11.状态管理</h1> <h1 id="_12-登录实现"><a href="#_12-登录实现" class="header-anchor">#</a> 12.登录实现</h1> <h1 id="_13-异步获取动态菜单路由"><a href="#_13-异步获取动态菜单路由" class="header-anchor">#</a> 13.异步获取动态菜单路由</h1> <h1 id="_14-实现用户增删改查"><a href="#_14-实现用户增删改查" class="header-anchor">#</a> 14.实现用户增删改查</h1> <h1 id="_15-rbac-权限设计"><a href="#_15-rbac-权限设计" class="header-anchor">#</a> 15.RBAC 权限设计</h1> <h1 id="_16-用户菜单权限实现"><a href="#_16-用户菜单权限实现" class="header-anchor">#</a> 16.用户菜单权限实现</h1> <h1 id="_17-自定义注解-切面-aop-实现数据权限过滤"><a href="#_17-自定义注解-切面-aop-实现数据权限过滤" class="header-anchor">#</a> 17.自定义注解 + 切面 AOP 实现数据权限过滤</h1> <h1 id="_18-接口权限实现"><a href="#_18-接口权限实现" class="header-anchor">#</a> 18.接口权限实现</h1> <h1 id="_19-按钮权限控制"><a href="#_19-按钮权限控制" class="header-anchor">#</a> 19.按钮权限控制</h1> <h1 id="_20-数据脱敏"><a href="#_20-数据脱敏" class="header-anchor">#</a> 20.数据脱敏</h1></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9e59f384.js" defer></script><script src="/assets/js/2.61252cf6.js" defer></script><script src="/assets/js/13.a9ff20a6.js" defer></script>
  </body>
</html>
